package adv6;

//银行账号
public class Account {
	private String name;
	private int money;

	public Account(String n, int m) {
		this.name = n;
		this.money = m;
	}

	// 取钱
	public synchronized boolean takeMoney(int m) {
		// synchronized (this) {
		if (m <= money) {
			try {
				// sleep不释放锁
				Thread.sleep((long) (50 * Math.random()));
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			money -= m;
			return true;
		}
		// }
		return false;

	}

	public void deposit(int m) {
		this.money += m;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getMoney() {
		return money;
	}

	public void setMoney(int money) {
		this.money = money;
	}
}
